package com.atguigu.chapter11

object StreamDemo01 {

  def main(args: Array[String]): Unit = {
    val stream1 = numsForm(1)
    println(stream1) // (1,?)
    //取出第一个元素
    println("head=" + stream1.head) // 1
    println(stream1.tail) // 2
    println(stream1) //? (1,2,...)
    println(numsForm(5).map(multi)) //(25, ?)

  } //看一个应用案例
  def multi(x: BigInt): BigInt = {
    x * x
  }

  //创建Stream
  def numsForm(n: BigInt): Stream[BigInt] = {
    n #:: numsForm(n + 1)
  }
}
